//封装分类业务
import { getCategoryApi } from "@/apis/category";
import { ref, onMounted, watch } from "vue";
import { useRoute } from 'vue-router';

export function useCatrgory() {
    // 获取路由参数id
    const route = useRoute()
    const categoryData = ref({})
    const getCategory = async () => {
        const res = await getCategoryApi(route.params.id)
        categoryData.value = res.result
    }
    //面包屑不是响应式，需要监听id是否改变引起面包屑刷新
    watch(
        () => route.params.id,
        (newId) => {
            if (newId) {
                getCategory()
            }
        }
    )
    onMounted(() => getCategory())

    return {
        categoryData
    }


}
